#pragma once
#include <pthread.h>
#include <string>
#include <map>
#include <functional>
#include <climits>
#include <iostream>

class Task
{
public:
    Task() {}
    Task(int left, int right, char oper)
        : _left(left), _right(right), _oper(oper)
    {
        cmdOP =
        {
            {'+', [](int x, int y){ return x + y; }},
            {'-', [](int x, int y){ return x - y; }},
            {'*', [](int x, int y){ return x * y; }},
            {'/', [](int x, int y){ return y == 0 ? INT_MAX : x / y; }}
        };
    }
    void Run()
    {
        _result = cmdOP[_oper](_left, _right);

        // switch (_oper)
        // {
        // case '+':_result = _left + _right;break;
        // case '-':_result = _left - _right;break;
        // case '*':_result = _left * _right;break;
        // case '/':
        // {
        //     if (_right != 0)
        //         _result = _left / _right;
        // }
        // break;
        // default:
        //     break;
        // }
    }
    void operator()()
    {
        Run();
    }
    std::string PrintTask()
    {
        std::string tmp;
        tmp += std::to_string(_left);
        tmp += _oper;
        tmp += std::to_string(_right);
        tmp += '=';
        // std::cout<<std::endl<< tmp << std::endl; //Debug
        return tmp;
    }
    std::string PrintResult()
    {
        std::string tmp;
        tmp += std::to_string(_left);
        tmp += _oper;
        tmp += std::to_string(_right);
        tmp += '=';
        tmp += std::to_string(_result);
        return tmp;
    }
    static const std::string opers; // 注意这个得是public
private:
    int _left;
    int _right;
    int _result;
    char _oper;
    std::map<char, std::function<int(int, int)>> cmdOP;
};

const std::string Task::opers = "+-*/";
